﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using MarsExplorerWebSite.Model;

namespace MarsExplorerWebSite.Functions
{
    public class getTeam : FunctionBase
    {
        private MarsExplorerEntities dbContext;
        public int TeamID { get; set; }
        public getTeam(HttpContext context)
            : base(context)
        {
            InitializeProperties();
        }

        public override string Execute()
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                Team t = (from x in dbContext.Teams where x.TeamID == TeamID select x).FirstOrDefault();



                sb.Append(t.TeamID + ",");
                sb.Append(t.Name + ",");
                sb.Append(t.Route.Name + ",");
                sb.Append(t.Minerals + ",");
                sb.Append(t.Credits + ";");

                return sb.ToString();
            }
            catch (Exception)
            {

                return "Error";
            }
           
        }

        public override void InitializeProperties()
        {
            try
            {
                dbContext = new MarsExplorerEntities();
                TeamID = Convert.ToInt32(Parameters["teamid"]);
            }
            catch (Exception e)
            {
                string message = "";
#if DEBUG
                message += " : " + e.ToString();

#endif

               
            }
        }
    }
}